package oa.hleast.xswl.mapper.activity;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import oa.hleast.xswl.pojo.domain.activity.CmsActivityCalendar;
import oa.hleast.xswl.pojo.domain.activity.CmsCommonActivity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CmsCommonActivityMapper extends BaseMapper<CmsCommonActivity> {

    @Select("select c.* from" +
            "( select activity_id  from cms_activity_manager_user where manager_user_id = #{managerUserId}) u " +
            "left join cms_common_activity c  on c.id = u.activity_id where deleted = 0;")
    List<CmsCommonActivity> findAllManagerActivity(Long managerUserId);

    @Select("select c.* from" +
            "( select activity_id  from cms_activity_manager_user where manager_user_id = #{managerUserId}) u " +
            "left join (select * from cms_common_activity where activity_type_id  = #{venueActivityTypeId} )c  " +
            "on c.id = u.activity_id where deleted = 0;")
    List<CmsCommonActivity> findByManagerUserAndVenue(Long managerUserId, Long venueActivityTypeId);

    @Select("SELECT cac.* FROM ( " +
            "    SELECT * FROM cms_activity_manager_user WHERE manager_user_id = #{teacherUserId} AND deleted = 0) mu " +
            "LEFT JOIN ( " +
            "    SELECT * FROM cms_activity_calendar WHERE to_days(activity_start_date) = to_days(now()) AND activity_type_id = #{activityTypeId} AND deleted = 0) cac  " +
            "ON mu.activity_id = cac.activity_id ;")
    List<CmsActivityCalendar> findTodayManagerActivityCalendar(Long teacherUserId, Long activityTypeId);

    @Update("update cms_common_activity set sign_in_num = sign_in_num  +1 where id= #{scenesId} ")
    void updateSingUpNumber(Long scenesId);
}